package com.colin.dubbo.strategy.impl;

import com.alibaba.fastjson.JSONObject;
import com.colin.dubbo.annotation.MethodName;
import com.colin.dubbo.business.request.Demo2Request;
import com.colin.dubbo.business.response.CommonResponse;
import com.colin.dubbo.datasource.DataSource;
import com.colin.dubbo.datasource.DataSourceTypeEnum;
import com.colin.dubbo.entity.dto.RequestDto;
import com.colin.dubbo.entity.po.AccountPO;
import com.colin.dubbo.enums.MethodEnum;
import com.colin.dubbo.mapper.AccountMapper;
import com.colin.dubbo.strategy.HandleStrategy;
import com.colin.dubbo.util.LogUtil;
import org.checkerframework.checker.units.qual.A;

import javax.annotation.Resource;

/**
 * 示例策略二
 */
@MethodName(method = MethodEnum.DEMO2)
public class Demo2HandleStrategy implements HandleStrategy {

    @Resource
    private AccountMapper accountMapper;
    
    @Override
    @DataSource(dataSourceType = DataSourceTypeEnum.MYSQL_SLAVE)
    public CommonResponse handle(RequestDto request) throws Exception {
        CommonResponse response = CommonResponse.success();
        Demo2Request demo1Request = (Demo2Request)request;
        
        LogUtil.info("demo2:{}", JSONObject.toJSONString(demo1Request));

        AccountPO query = new AccountPO();
        query.setAccountId(37L);
        AccountPO account = accountMapper.selectByPrimaryKey(query);
        LogUtil.info("account:{}", JSONObject.toJSONString(account));

        response.setData(request);
        return response;
    }
}
